<?php

/**
 * Class for render product detail * 
 * 
 * @author Tuan Nguyen <nganhtuan63@gmail.com>
 * @version 1.0
 * @package common.blocks.product_detail */
class ProductDetailBlock extends CWidget {

    //Do not delete these attr block, page and errors
    public $id = 'product_detail';
    public $block = null;
    public $errors = array();
    public $page = null;
    public $layout_asset = '';

    public function setParams($params) {
        return;
    }

    public function run() {
        $this->renderContent();
    }

    protected function renderContent() {

        if (isset($this->block) && ($this->block != null)) {
            //Start working with product detail here
            $params = b64_unserialize($this->block['params']);
            $this->setParams($params);
            $request = Yii::app()->request;

            $slug = $request->getParam('slug', '');
            $term = NULL;
            $object = NULL;
            $model = new FormBuynow();
            $object = Object::model()->GetObjectByObjectSlug($slug);
            if ($slug == $object->object_slug) {
                Yii::app()->controller->pageTitle = CHtml::encode($object->object_name);
                Yii::app()->controller->description = CHtml::encode($object->object_description);
                Yii::app()->controller->keywords = CHtml::encode($object->object_keywords);
                Yii::app()->controller->change_title = true;
            } else {
                throw new CHttpException('404', t('site', 'Page not found'));
            }

            $this->render(BlockRenderWidget::setRenderOutput($this), array(
                'object' => $object, 'pid' => $object->object_id, 'model' => $model,
            ));
        } else {
            echo '';
        }
    }

    public function validate() {
        return true;
    }

    public function params() {
        return array();
    }

    public function beforeBlockSave() {
        return true;
    }

    public function afterBlockSave() {
        return true;
    }

}

?>